package edu.neu.cs6515.player.strategy;

import java.util.List;

import edu.neu.cs6515.xml.Placement;
import edu.neu.cs6515.xml.Score;
import edu.neu.cs6515.xml.Tile;

/**
 * Implementation of non dynamic strategy, strictly executes
 * given placements in order
 */
public class SimpleStepStrategy extends AbstractStrategy {

    private static final String RAN_OUT_OF_ACTIONS_ERROR = "Ran out of actions";

    /**
     * list index of the move the player is going to make next
     */
    private int nextPlacementIndex = 0;

    private final List<Placement> allPlacements;

    /**
     * Initialize class with list of placements
     * @param allPlacements placements to be recommended by strategy
     */
    public SimpleStepStrategy(final List<Placement> allPlacements) {
        this.allPlacements = allPlacements;
    }

    @Override
    public Placement getNextMove(final List<Tile> tilesInHand, final int numberOfPlayers,
            final List<Placement> placementsSofar, final Score scoreBeforePlacement) {
        if (nextPlacementIndex >= allPlacements.size()) {
            throw new StrategyException(RAN_OUT_OF_ACTIONS_ERROR);
        }
        return allPlacements.get(nextPlacementIndex++);
    }

}
